package com.beiben.workflow.controller;

import com.beiben.workflow.domain.WfCheck;
import com.beiben.workflow.domain.WfCheckVo;
import com.beiben.workflow.service.IWfCheckService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批记录Controller
 *
 * @author 熊国强
 * @date 2020-12-17
 */
@RestController
@RequestMapping("/workflow/check")
public class WfCheckController extends BaseController {

    @Autowired
    private IWfCheckService wfCheckService;

    /**
     * 查询审批记录列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(WfCheck wfCheck) {
        startPage();
        List<WfCheck> list = wfCheckService.selectWfCheckList(wfCheck);
        return getDataTable(list);
    }

    /**
     * 导出审批记录列表
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:export')")
    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WfCheck wfCheck) {
        List<WfCheck> list = wfCheckService.selectWfCheckList(wfCheck);
        ExcelUtil<WfCheck> util = new ExcelUtil<WfCheck>(WfCheck.class);
        return util.exportExcel(list, "check");
    }

    /**
     * 获取审批记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId) {
        return AjaxResult.success(wfCheckService.selectWfCheckById(checkId));
    }

    /**
     * 新增审批记录
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:add')")
    @Log(title = "审批记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfCheck wfCheck) {
        return toAjax(wfCheckService.insertWfCheck(wfCheck));
    }

    /**
     * 修改审批记录
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:edit')")
    @Log(title = "审批记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfCheck wfCheck) {
        return toAjax(wfCheckService.updateWfCheck(wfCheck));
    }

    /**
     * 删除审批记录
     */
    @PreAuthorize("@ss.hasPermi('workflow:check:remove')")
    @Log(title = "审批记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds) {
        return toAjax(wfCheckService.deleteWfCheckByIds(checkIds));
    }

    /**
     * 我的审批
     *
     * @return
     */
    @GetMapping("/approveList")
    @PreAuthorize("@ss.hasPermi('workflow:check:list')")
    public TableDataInfo approveList(WfCheckVo wfCheckVo) {
        startPage();
        List<WfCheckVo> wfChecks = wfCheckService.approveList(wfCheckVo);
        return getDataTable(wfChecks);
    }

    /**
     * 获取审批记录统计信息
     */
    @GetMapping(value = "/getCheckCount")
    public AjaxResult getCheckCount() {
        return AjaxResult.success(wfCheckService.selectWfCheckCount());
    }

}
